<?php


abstract class BasePeticion extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $prioridad_id;


	
	protected $usuario_id;


	
	protected $seccion_id;


	
	protected $tipo_peticion_id;


	
	protected $resumen;


	
	protected $descripcion;


	
	protected $fecha;


	
	protected $ignorar = 0;


	
	protected $solucion;


	
	protected $solucionado;


	
	protected $discusion;


	
	protected $fecha_solucion;

	
	protected $aPrioridad;

	
	protected $aUsuario;

	
	protected $aSeccion;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getPrioridadId()
	{

		return $this->prioridad_id;
	}

	
	public function getUsuarioId()
	{

		return $this->usuario_id;
	}

	
	public function getSeccionId()
	{

		return $this->seccion_id;
	}

	
	public function getTipoPeticionId()
	{

		return $this->tipo_peticion_id;
	}

	
	public function getResumen()
	{

		return $this->resumen;
	}

	
	public function getDescripcion()
	{

		return $this->descripcion;
	}

	
	public function getFecha($format = 'Y-m-d')
	{

		if ($this->fecha === null || $this->fecha === '') {
			return null;
		} elseif (!is_int($this->fecha)) {
						$ts = strtotime($this->fecha);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha] as date/time value: " . var_export($this->fecha, true));
			}
		} else {
			$ts = $this->fecha;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getIgnorar()
	{

		return $this->ignorar;
	}

	
	public function getSolucion()
	{

		return $this->solucion;
	}

	
	public function getSolucionado()
	{

		return $this->solucionado;
	}

	
	public function getDiscusion()
	{

		return $this->discusion;
	}

	
	public function getFechaSolucion($format = 'Y-m-d H:i:s')
	{

		if ($this->fecha_solucion === null || $this->fecha_solucion === '') {
			return null;
		} elseif (!is_int($this->fecha_solucion)) {
						$ts = strtotime($this->fecha_solucion);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_solucion] as date/time value: " . var_export($this->fecha_solucion, true));
			}
		} else {
			$ts = $this->fecha_solucion;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = PeticionPeer::ID;
		}

	} 
	
	public function setPrioridadId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->prioridad_id !== $v) {
			$this->prioridad_id = $v;
			$this->modifiedColumns[] = PeticionPeer::PRIORIDAD_ID;
		}

		if ($this->aPrioridad !== null && $this->aPrioridad->getId() !== $v) {
			$this->aPrioridad = null;
		}

	} 
	
	public function setUsuarioId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->usuario_id !== $v) {
			$this->usuario_id = $v;
			$this->modifiedColumns[] = PeticionPeer::USUARIO_ID;
		}

		if ($this->aUsuario !== null && $this->aUsuario->getId() !== $v) {
			$this->aUsuario = null;
		}

	} 
	
	public function setSeccionId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->seccion_id !== $v) {
			$this->seccion_id = $v;
			$this->modifiedColumns[] = PeticionPeer::SECCION_ID;
		}

		if ($this->aSeccion !== null && $this->aSeccion->getId() !== $v) {
			$this->aSeccion = null;
		}

	} 
	
	public function setTipoPeticionId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->tipo_peticion_id !== $v) {
			$this->tipo_peticion_id = $v;
			$this->modifiedColumns[] = PeticionPeer::TIPO_PETICION_ID;
		}

	} 
	
	public function setResumen($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->resumen !== $v) {
			$this->resumen = $v;
			$this->modifiedColumns[] = PeticionPeer::RESUMEN;
		}

	} 
	
	public function setDescripcion($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->descripcion !== $v) {
			$this->descripcion = $v;
			$this->modifiedColumns[] = PeticionPeer::DESCRIPCION;
		}

	} 
	
	public function setFecha($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha !== $ts) {
			$this->fecha = $ts;
			$this->modifiedColumns[] = PeticionPeer::FECHA;
		}

	} 
	
	public function setIgnorar($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->ignorar !== $v || $v === 0) {
			$this->ignorar = $v;
			$this->modifiedColumns[] = PeticionPeer::IGNORAR;
		}

	} 
	
	public function setSolucion($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->solucion !== $v) {
			$this->solucion = $v;
			$this->modifiedColumns[] = PeticionPeer::SOLUCION;
		}

	} 
	
	public function setSolucionado($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->solucionado !== $v) {
			$this->solucionado = $v;
			$this->modifiedColumns[] = PeticionPeer::SOLUCIONADO;
		}

	} 
	
	public function setDiscusion($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->discusion !== $v) {
			$this->discusion = $v;
			$this->modifiedColumns[] = PeticionPeer::DISCUSION;
		}

	} 
	
	public function setFechaSolucion($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_solucion] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_solucion !== $ts) {
			$this->fecha_solucion = $ts;
			$this->modifiedColumns[] = PeticionPeer::FECHA_SOLUCION;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->prioridad_id = $rs->getInt($startcol + 1);

			$this->usuario_id = $rs->getInt($startcol + 2);

			$this->seccion_id = $rs->getInt($startcol + 3);

			$this->tipo_peticion_id = $rs->getInt($startcol + 4);

			$this->resumen = $rs->getString($startcol + 5);

			$this->descripcion = $rs->getString($startcol + 6);

			$this->fecha = $rs->getDate($startcol + 7, null);

			$this->ignorar = $rs->getInt($startcol + 8);

			$this->solucion = $rs->getString($startcol + 9);

			$this->solucionado = $rs->getInt($startcol + 10);

			$this->discusion = $rs->getString($startcol + 11);

			$this->fecha_solucion = $rs->getTimestamp($startcol + 12, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 13; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Peticion object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(PeticionPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			PeticionPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(PeticionPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aPrioridad !== null) {
				if ($this->aPrioridad->isModified()) {
					$affectedRows += $this->aPrioridad->save($con);
				}
				$this->setPrioridad($this->aPrioridad);
			}

			if ($this->aUsuario !== null) {
				if ($this->aUsuario->isModified()) {
					$affectedRows += $this->aUsuario->save($con);
				}
				$this->setUsuario($this->aUsuario);
			}

			if ($this->aSeccion !== null) {
				if ($this->aSeccion->isModified()) {
					$affectedRows += $this->aSeccion->save($con);
				}
				$this->setSeccion($this->aSeccion);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = PeticionPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += PeticionPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aPrioridad !== null) {
				if (!$this->aPrioridad->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aPrioridad->getValidationFailures());
				}
			}

			if ($this->aUsuario !== null) {
				if (!$this->aUsuario->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUsuario->getValidationFailures());
				}
			}

			if ($this->aSeccion !== null) {
				if (!$this->aSeccion->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aSeccion->getValidationFailures());
				}
			}


			if (($retval = PeticionPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = PeticionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getPrioridadId();
				break;
			case 2:
				return $this->getUsuarioId();
				break;
			case 3:
				return $this->getSeccionId();
				break;
			case 4:
				return $this->getTipoPeticionId();
				break;
			case 5:
				return $this->getResumen();
				break;
			case 6:
				return $this->getDescripcion();
				break;
			case 7:
				return $this->getFecha();
				break;
			case 8:
				return $this->getIgnorar();
				break;
			case 9:
				return $this->getSolucion();
				break;
			case 10:
				return $this->getSolucionado();
				break;
			case 11:
				return $this->getDiscusion();
				break;
			case 12:
				return $this->getFechaSolucion();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = PeticionPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getPrioridadId(),
			$keys[2] => $this->getUsuarioId(),
			$keys[3] => $this->getSeccionId(),
			$keys[4] => $this->getTipoPeticionId(),
			$keys[5] => $this->getResumen(),
			$keys[6] => $this->getDescripcion(),
			$keys[7] => $this->getFecha(),
			$keys[8] => $this->getIgnorar(),
			$keys[9] => $this->getSolucion(),
			$keys[10] => $this->getSolucionado(),
			$keys[11] => $this->getDiscusion(),
			$keys[12] => $this->getFechaSolucion(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = PeticionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setPrioridadId($value);
				break;
			case 2:
				$this->setUsuarioId($value);
				break;
			case 3:
				$this->setSeccionId($value);
				break;
			case 4:
				$this->setTipoPeticionId($value);
				break;
			case 5:
				$this->setResumen($value);
				break;
			case 6:
				$this->setDescripcion($value);
				break;
			case 7:
				$this->setFecha($value);
				break;
			case 8:
				$this->setIgnorar($value);
				break;
			case 9:
				$this->setSolucion($value);
				break;
			case 10:
				$this->setSolucionado($value);
				break;
			case 11:
				$this->setDiscusion($value);
				break;
			case 12:
				$this->setFechaSolucion($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = PeticionPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setPrioridadId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setUsuarioId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setSeccionId($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setTipoPeticionId($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setResumen($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDescripcion($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setFecha($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setIgnorar($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setSolucion($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setSolucionado($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setDiscusion($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setFechaSolucion($arr[$keys[12]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(PeticionPeer::DATABASE_NAME);

		if ($this->isColumnModified(PeticionPeer::ID)) $criteria->add(PeticionPeer::ID, $this->id);
		if ($this->isColumnModified(PeticionPeer::PRIORIDAD_ID)) $criteria->add(PeticionPeer::PRIORIDAD_ID, $this->prioridad_id);
		if ($this->isColumnModified(PeticionPeer::USUARIO_ID)) $criteria->add(PeticionPeer::USUARIO_ID, $this->usuario_id);
		if ($this->isColumnModified(PeticionPeer::SECCION_ID)) $criteria->add(PeticionPeer::SECCION_ID, $this->seccion_id);
		if ($this->isColumnModified(PeticionPeer::TIPO_PETICION_ID)) $criteria->add(PeticionPeer::TIPO_PETICION_ID, $this->tipo_peticion_id);
		if ($this->isColumnModified(PeticionPeer::RESUMEN)) $criteria->add(PeticionPeer::RESUMEN, $this->resumen);
		if ($this->isColumnModified(PeticionPeer::DESCRIPCION)) $criteria->add(PeticionPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(PeticionPeer::FECHA)) $criteria->add(PeticionPeer::FECHA, $this->fecha);
		if ($this->isColumnModified(PeticionPeer::IGNORAR)) $criteria->add(PeticionPeer::IGNORAR, $this->ignorar);
		if ($this->isColumnModified(PeticionPeer::SOLUCION)) $criteria->add(PeticionPeer::SOLUCION, $this->solucion);
		if ($this->isColumnModified(PeticionPeer::SOLUCIONADO)) $criteria->add(PeticionPeer::SOLUCIONADO, $this->solucionado);
		if ($this->isColumnModified(PeticionPeer::DISCUSION)) $criteria->add(PeticionPeer::DISCUSION, $this->discusion);
		if ($this->isColumnModified(PeticionPeer::FECHA_SOLUCION)) $criteria->add(PeticionPeer::FECHA_SOLUCION, $this->fecha_solucion);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(PeticionPeer::DATABASE_NAME);

		$criteria->add(PeticionPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setPrioridadId($this->prioridad_id);

		$copyObj->setUsuarioId($this->usuario_id);

		$copyObj->setSeccionId($this->seccion_id);

		$copyObj->setTipoPeticionId($this->tipo_peticion_id);

		$copyObj->setResumen($this->resumen);

		$copyObj->setDescripcion($this->descripcion);

		$copyObj->setFecha($this->fecha);

		$copyObj->setIgnorar($this->ignorar);

		$copyObj->setSolucion($this->solucion);

		$copyObj->setSolucionado($this->solucionado);

		$copyObj->setDiscusion($this->discusion);

		$copyObj->setFechaSolucion($this->fecha_solucion);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new PeticionPeer();
		}
		return self::$peer;
	}

	
	public function setPrioridad($v)
	{


		if ($v === null) {
			$this->setPrioridadId(NULL);
		} else {
			$this->setPrioridadId($v->getId());
		}


		$this->aPrioridad = $v;
	}


	
	public function getPrioridad($con = null)
	{
		if ($this->aPrioridad === null && ($this->prioridad_id !== null)) {
						$this->aPrioridad = PrioridadPeer::retrieveByPK($this->prioridad_id, $con);

			
		}
		return $this->aPrioridad;
	}

	
	public function setUsuario($v)
	{


		if ($v === null) {
			$this->setUsuarioId(NULL);
		} else {
			$this->setUsuarioId($v->getId());
		}


		$this->aUsuario = $v;
	}


	
	public function getUsuario($con = null)
	{
		if ($this->aUsuario === null && ($this->usuario_id !== null)) {
						$this->aUsuario = UsuarioPeer::retrieveByPK($this->usuario_id, $con);

			
		}
		return $this->aUsuario;
	}

	
	public function setSeccion($v)
	{


		if ($v === null) {
			$this->setSeccionId(NULL);
		} else {
			$this->setSeccionId($v->getId());
		}


		$this->aSeccion = $v;
	}


	
	public function getSeccion($con = null)
	{
		if ($this->aSeccion === null && ($this->seccion_id !== null)) {
						$this->aSeccion = SeccionPeer::retrieveByPK($this->seccion_id, $con);

			
		}
		return $this->aSeccion;
	}

} 